/*******************************************************************************

    copyright:  Copyright (c) 2007 Matthias Walter. All rights reserved

    license:    BSD style: $(LICENSE)

    version:    Initial release: May 2007

    author:     Matthias Walter

*******************************************************************************/

module fcgi.Base;

extern (C)
{

/***********************************************************************

    Stop accepting requests.

***********************************************************************/

void OS_ShutdownPending ();

/***********************************************************************

    Write data to stream on OS level.

    Params:

    fd      = File Descriptor to write to
    buffer  = Buffer to write
    size    = Size of buffer

    Returns:

    0 on success, errorcode otherwise

***********************************************************************/

int OS_Write (int fd, void* buffer, int size);

/***********************************************************************

    Read data to stream on OS level.

    Params:

    fd      = File Descriptor to read from
    buffer  = Buffer to write
    size    = Size of buffer

    Returns:

    0 on success, errorcode otherwise

***********************************************************************/

int OS_Read (int fd, void *buffer, int size);

/***********************************************************************

    Tests, whether we are a CGI or FastCGI application.

    Returns:

    true for FastCGI, false for CGI

***********************************************************************/

bool OS_IsFcgi (int fd);

/***********************************************************************

    Closes a listening descriptor.

    Params:

    fd      = File Descriptor to close

***********************************************************************/

void OS_IpcClose (int fd);

/***********************************************************************

    Creates a domain socket or TCP/IP socket bound to localhost.

    Params:

    path      = host/port to bind to
    backlog   = Size of queue for pending connections

    Returns:

    File Descriptor for the created socket

***********************************************************************/

int OS_CreateLocalIpcFd (char* path, int backlog);

/***********************************************************************

    Initializes the FastCGI library.

    Params:

    stdioFileDescriptors = the 3 standard file descriptors or null

    Returns:

    0 for success, errorcode otherwise

***********************************************************************/

int OS_LibInit (int* stdioFileDescriptors);

/***********************************************************************

    Accepts a connection on a listening socket.

    Params:

    listenSock              = Socket Descriptor, must be in listening state
    failOnInterrupt         = Flag, whether to fail on interrupt or try again
    webServerAddressList    = list of valid webserver addresses

    Returns:

    Stream Descriptor

***********************************************************************/

int OS_Accept (int listenSock, int failOnInterrupt, char* webServerAddressList);

}
